// 将base64转换为blob

function dataURLtoBlob(dataurl) {
  let arr = dataurl.split(",");
  let mime = arr[0].match(/:(.*?);/)[1];
  let bstr = window.atob(arr[1]);
  let n = bstr.length;
  let u8arr = new Uint8Array(n);
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n);
  }
  return new Blob([u8arr], {type: mime});
}

// 将blob转换为file
function blobToFile(theBlob, fileName) {
  theBlob.lastModifiedDate = new Date();
  theBlob.name = fileName;
  return theBlob;
}

// 将base64转换为img的 URL
export function base64DataToImgURL(img_base64) {
  img_base64 = "data:image/png;base64,"+img_base64;
  // base64转blob
  let blob_data = dataURLtoBlob(img_base64);
  let image_file = blobToFile(blob_data, '图像-'+ Math.floor(Math.random()*100000000000)+'.jpg');
  console.log(image_file)

  return URL.createObjectURL(image_file);
}
